<?php
class AdvisoryAction extends BaseAction{
	// 首页
	public function index(){
		$sortcode 		= t($_REQUEST['sortcode']);
		$ownertype	 	= t($_REQUEST['ownertype']);
		$hadanswered	= t($_REQUEST['hadanswered']);
		//dump($_REQUEST);
		if(empty($sortcode))$sortcode='suggest';
		if(empty($ownertype))$ownertype='all';
		if(empty($hadanswered))$hadanswered='all';
		$pagedata = service('Common')->searchAdvisory4Sys($sortcode,$ownertype,$hadanswered,null,3);
		$this->assign('pagedata', $pagedata);
		$this->assign('sortcode', $sortcode);
		$this->assign('ownertype', $ownertype);
		$this->assign('hadanswered', $hadanswered);
		$this->display();
	}
	
	public function answer(){
		$id = $_REQUEST['advid'];
		$advisory = M('Dialogue')->where('id='.$id)->find();
		if(empty($advisory))$this->error('数据不存在!');
		$this->assign('advisory', $advisory);
		$this->display();
	}
	
	public function doanswer(){
		$id = $_REQUEST['advid'];
		$answer_text	= t($_REQUEST['answer_text']);
		$no=model('Dialogue')->updateDialogue($id,$answer_text,$this->adminId);
		if($no){
			$this->success('回复成功');
		}else{
			$this->error('回复失败');
		}
	}
}
?>